﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using Tulde.Core;
using Tulde.MP3tunes.Model;


namespace MP3tunes.LockerPlayer.Pages
{
    public partial class AlbumPage : PhoneApplicationPage
    {
        protected Artist SelectedArtist { get; private set; }


        public AlbumPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {


            base.OnNavigatedTo(e);
            this.SelectedArtist = NavigationContext.GetViewModelFromQueryParameters<Artist>();
            this.listAlbums.SelectionChanged -=new SelectionChangedEventHandler(listAlbums_SelectionChanged);
            this.artistLabel.Text = this.SelectedArtist.ArtistName;
            this.statusProgress.IsIndeterminate = true;
            Tulde.MP3tunes.Mp3TunesMusicService.GetArtistAlbums(this.SelectedArtist, albums =>
            {
                this.listAlbums.DataContext = albums.Albums;
                this.statusProgress.IsIndeterminate = false;
                this.listAlbums.SelectionChanged += new SelectionChangedEventHandler(listAlbums_SelectionChanged);
            });

        }

        private void listAlbums_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Album album = this.listAlbums.SelectedItem as Album;
            NavigationService.NavigateWithViewModels("/Pages/MediaPlayer.xaml", album);
        }

        private void AppMenu_OnNavigate(object sender, UserControls.AppMenuEventArg e)
        {
            this.NavigationService.NavigateWithViewModels(e.Destination);
        }

        private void Image_ImageOpened(object sender, RoutedEventArgs e)
        {
            var image = sender as Image;
           // image.SetValue(BackgroundProperty, Colors.Red);
        }
    }
}